<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\store\controller;

use app\store\model\Order as OrderModel;
use think\facade\Db;
use think\response\Json;

/**
 * 订单管理
 * Class Order
 * @package app\store\controller
 */
class Order extends Controller
{

    /**
     * 订单列表-支付记录
     * @param string $dataType
     * @return Json
     */
    public function getPayLog(int $orderId): Json
    {
        // 订单列表
        $model  = new OrderModel;


        $list = $model->getPayLog($orderId);
        return $this->renderSuccess(compact('list'));
    }

    /**
     * 订单列表-代泊车
     * @param string $dataType
     * @return Json
     */
    public function listPark(string $dataType): Json
    {
        // 订单列表
        $model = new OrderModel;
        $list  = $model->getListPark($this->request->param());
        return $this->renderSuccess(compact('dataType', 'list'));
    }

    /**
     * 订单列表-陪护
     * @param string $dataType
     * @return Json
     */
    public function listPeihu(string $dataType): Json
    {
        // 订单列表
        $model = new OrderModel;
        $list  = $model->getListPeihu($this->request->param());
        return $this->renderSuccess(compact('dataType', 'list'));
    }
    /**
     * 订单列表
     * @param string $dataType
     * @return Json
     */
    public function list(string $dataType): Json
    {
        // 订单列表
        $model = new OrderModel;
        $list  = $model->getList($this->request->param());
        return $this->renderSuccess(compact('dataType', 'list'));
    }

    /**
     * 订单详情
     * @param int $orderId
     * @return Json
     */
    public function detail(int $orderId): Json
    {
        // 订单详情
        $model = new OrderModel;
        if (! $detail = $model->getDetail($orderId)) {
            return $this->renderError('未找到该订单记录');
        }

        return $this->renderSuccess(compact('detail'));
    }
    public function detail_peihu(int $orderId): Json
    {
        // 订单详情
        $model = new OrderModel;
        if (! $detail = $model->getDetailPeihu($orderId)) {
            return $this->renderError('未找到该订单记录');
        }
        return $this->renderSuccess(compact('detail'));
    }
    public function dengjiDetail(int $orderId): Json
    {
        // 订单详情
        $detail = Db::name('jia_order_check')->where('order_id', $orderId)->order('log_id desc')->find();
        if ($detail) {
            $detail['content'] = json_decode($detail['content'], true);
            $detail['label']   = json_decode($detail['label'], true);
        } else {
            $detail['content'] = [];
            $detail['label']   = [];
        }

        return $this->renderSuccess(compact('detail'));
    }
}
